import axios from 'axios'
import { CHANGE_INPUT, ADD_ITEM, DELETE_ITEM, GET_LIST, GET_MY_LIST } from './actionTypes'

export const changeInputAction = value => ({
  type: CHANGE_INPUT,
  value
})

export const addItemAction = () => ({
  type: ADD_ITEM
})

export const deleteItemAction = index => ({
  type: DELETE_ITEM,
  index
})

export const getListAction = data => ({
  type: GET_LIST,
  data
})

export const getToDoList = () => {
  return dispatch => {
    axios.get('https://www.easy-mock.com/mock/5f8fd789bcca63581f44c444/redux/getList').then(res => {
      const data = res.data.data.list
      const action = getListAction(data)
      dispatch(action)
    })
  }
}

export const getMyListAction = () => ({
  type: GET_MY_LIST
})
